
/*
 * @Author: your name
 * @Date: 2020-05-14 10:31:50
 * @LastEditTime: 2020-10-25 18:33:39
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /yigo/src/Pages/OrderListScreen.js
 */
import React, { Component } from 'react'
import { View, Text ,Image, TouchableOpacity,StyleSheet} from 'react-native'
import { connect } from 'react-redux'
import SearchBar from 'react-native-material-design-searchbar';
import CustomFlatList from '../Utils/CustomFlatList'
import {foodList} from '../Actions/UserActions'


class OrderListScreen extends Component {
    constructor(props) {
        super(props)
        
          this.state = {
            keywords:null,       //搜索关键字
            data:[]
        }
        this.page = 0;    // 默认第0页
    }
    componentWillMount() {
    }

    shouldComponentUpdate(nextProps, nextState) {
        if (this.props.isFetch && !nextProps.isFetch) {
            if (nextProps.code == 200) {
                console.log("返回值:",nextProps.data);
                let data = nextProps.data;
                this.setState({data})
    
            }
        }
        return true
    }

    onPress() {
        // this.props.foodList({a:'b'})

    }

    render() {
        let {isFetch} = this.props
        
        return (
            <View style={{flex:1}}>
                <Text onPress={this.onPress.bind(this)}>刷新</Text>
                <CustomFlatList 
                    renderItem={this._renderItem}
                    lookMoreClick={() => this.refreshData(true)}
                    data={this.state.data}>
                </CustomFlatList>
            </View>
        )
    }

    lookMoreClick = () => {
    
    }

    onSearchChange(keywords) {        
        this.setState({keywords})
    }  
    _renderItem = ({item,index}) => (

        <View style={{backgroundColor:'#F8F8F8',height:184}}>
            <View style={{backgroundColor:'#dcdcdc',height:1}}></View>
            <Image resizeMode='cover' style={{width:100, height:100,backgroundColor:'gray'}} source={{uri:API_ROOT + `api/showImage/upload/${item.FoodImage}`}}></Image>
            <Text>{item.BusinessName}</Text>
            <Text>{item.FoodName}</Text>
            <Text>{`${item.price}元`}</Text>
    
        </View>
     );
    _keyExtractor = (item, index) => item.id;

}

const mapStateToProps = (state) => {
    let { isFetch, code, data, msg} = state.UserInfo.foodList || '';    
    
    return { 
        isFetch, code, data, msg
            } 
}

const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        foodList: (paramter)=> dispatch(foodList(paramter))

    }
}

const styles = StyleSheet.create({
    textStyle:{
        marginTop:3,
        marginBottom:3,
        color:'#404040'
    }
  });

export default connect(mapStateToProps,mapDispatchToProps)(OrderListScreen)
